//miscellaneous test data

240,238,234,228,213, 189,154,113,70,30

249,189,0=147,117,0
hsl=0,0,0
hsl=45,100,97=46 100.0 48.8
hsl=47,100,57=46 100.0 29.9

249,89,0 0.5,0.33
147,117,0 149,122,0
-102,+28 1-0.3898=0.6102

a=99
99*2=198=opacity+42, new alpha=240

NewPixel=Pixel*(1-f)
roundup(1-254/99) 147...,117,0 (0.6102)

198,249,189,0 luminace = (0.2126*R + 0.7152*G + 0.0722*B) 52.9374+63.6528+0=117
240,147,117,0 luminace = 31.2522+83.6784+0=115

147,118,0=result1
142,109,0=result2

alpha=99
f=99/255=0.3882
1-f=0.6118
luminance 48.8 * 0.6118 = 29.9

alpha=28
f=28/255=0.1098
1-f=0.8902
luminance 48.8 * 0.8902 = 43.4

249,189,0=46 100.0 48.8
152,117,0=46 100.0 29.9

/*************************************************/

PERCEIVED DARKNESS:

//To simulate adding black or darkening a pixel by a factor f (where 0 is no change and 1 is full black), 
//use linear scaling: new_lum=old_lum*(1-f)

//formula to decrease luminance to simulate adding percentage of black (perceived darkness)

rgb to hsl, modify lum 
then hsl to rgb

//To calculate the lightness (L) value for HSL from RGB, you take the average of the maximum and minimum 
//values of the normalized red, green, and blue channels
r=(R/255); g=(G/255); b=(B/255);
//calculate lum
max = max(r,g,b)
min= min(r,g,b)
L= (max+min)/2;

//calculate hue
d=delta=(max-min);
if red-max res = ((g-b)/d mod 6); if green-max res = ((b-r)/d+2); if blue-max res = ((r-g)/d+4);
hue = roundup(res * 60);

//neon glow saturation is always 100%

///Need formula for converting HSL to RGB.


...
dst[idx + 3] = (alpha * 2) > 255 ? 255 : (alpha * 2); // boost intensity
//1.25 * (alpha *2) is same as (alpha * 2.5)

// 4. Composite original image on top, src=original image, msk=mask image, dst=resulting image
static void Composite_Image(unsigned char*src, unsigned char*msk, RGBColor glow)
{ 
    for (int y = 0; y < h; y++) 
    {
        for (int x = 0; x < w; x++) 
        {
            //linear pixel blending formula
            //float a = (alpha/255.0f), dst=(src*a) + (msk*(1-a))

            int s_idx = (y * w + x) * 4;                        
            unsigned char alpha = src[s_idx]; //old alpha //0,1,2,3=a,r,g,b
            if (alpha > 0 && < 255) 
            {
                if(src[s_idx + 1] > 0 && src[s_idx + 2] > 0 && src[s_idx + 3] > 0) //colored pixel, not black
                (
                    //linear pixel blending
                    float a = (alpha / 255.0f); //blend ratio
                    if(msk[s_idx + 1] == 0 && msk[s_idx + 2] == 0 && msk[s_idx + 3] == 0) //transparent
                    {
                        msk[s_idx + 1] = glow.r;
                        msk[s_idx + 2] = glow.g;
                        msk[s_idx + 3] = glow.b;
                    }
                    //new alpha should be <255
                    dst[s_idx] = (alpha * 2) > 255 ? 254 : (alpha * 2); // boost intensity
                    dst[s_idx + 1] = (unsigned char)(src[s_idx + 1] * a + msk[s_idx + 1] * (1.0f - a)); //red
                    dst[s_idx + 2] = (unsigned char)(src[s_idx + 2] * a + msk[s_idx + 2] * (1.0f - a)); //green
                    dst[s_idx + 3] = (unsigned char)(src[s_idx + 3] * a + msk[s_idx + 3] * (1.0f - a)); //blue
                }
                else if(src[s_idx + 1] == 0 && src[s_idx + 2] == 0 && src[s_idx + 3] == 0) //black shadow
                {
                    /* notes */
                    //formula to decrease luminance (perceived darkness) when compositing shadow & glow
                    //darken glow pixel to simulate adding black, see luminance formula.

                    //linear scaling for luminance values: new_lum=old_lum*(1-f) 
                    //f is the factor derived from (original alpha / 255)                    

                    //linear scaling of luminance
                    float lum; 
                    int new_lum;
                    float f = (alpha / 255.0f);
                    new_lum = (int)(lum*(1.0f-f));

                    //new alpha should be <255
                    dst[s_idx] = (alpha * 2) > 255 ? 254 : (alpha * 2); // boost intensity

                    /* notes */
                    //boosted glow alpha is (alpha *2); adjusted alpha is (alpha * 2.5)
                    //boost intensity of alpha: 1.25 * (alpha *2) is same as (alpha * 2.5)                    
                    //multiply by 5 then divide by 4 (1.25)
                    //alpha = (alpha * 5) / 4; //increasing alpha increases glow intensity
                }                 
            }
        }
    }
}
